<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .wrap {
            width: 480px;
            margin: 50px auto;
        }

        .wrap .nav {
            width: 480px;
            overflow: hidden;
            text-align: center;
            line-height: 40px;
            padding: 5px;
        }

        .wrap .nav li {
            float: left;
            width: 80px;
            border: 1px solid #333;
            box-sizing: border-box;
        }

        .wrap .nav li+li {
            border-left: 0;
        }

        .wrap .nav .active {
            background-color: aquamarine;
            color: #fff;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="nav">
            <!-- <li data-index="0">link_01</li>
            <li data-index="1">link_02</li>
            <li data-index="2">link_03</li>
            <li data-index="3">link_04</li>
            <li data-index="4">link_05</li>
            <li data-index="5">link_06</li> -->

            <li class="active">link_01</li>
            <li>link_02</li>
            <li>link_03</li>
            <li>link_04</li>
            <li>link_05</li>
            <li>link_06</li>
        </div>
    </div>
</body>
<script>

    /* 
        作业:
            1. 当前被点击的导航变为活跃状态, 其他的清除活跃状态
            (1) 先清除上一个,再把当前变为活跃状态
            (2) 先清除所有的,再把当前变为活跃状态

            2. tab栏切换

            3. 简易轮播

    
    */


    var liList = document.querySelectorAll(".nav li");
    console.log(liList);

    for (var i = 0; i < liList.length; i++) {
        var li = liList[i];
        li.onclick = function () {

            for (var j = 0; j < liList.length; j++) {
                liList[j].setAttribute("class","");
            }

            this.setAttribute("class","active");

        }
    }
    console.log("循环结束后", li, i);






</script>

</html>